package huachenxing.mimi520.option.widgets
{
	import com.cambright.mixpaint.Block;
	import com.cambright.stack.components.AlignmentLayoutComponent;
	import com.cambright.stack.components.LabelComponent;
	import com.cambright.stack.components.layout.Alignment;
	import com.cambright.stack.components.layout.Element;
	import com.cambright.stack.components.layout.Fill;
	
	import flash.geom.Rectangle;
	
	import mx.utils.StringUtil;
	
	import huachenxing.mimi520.option.commands.CloseQueryWindowCommand;
	import huachenxing.mimi520.option.models.AccountModel;
	import huachenxing.mimi520.option.models.QueryModel;
	import huachenxing.mimi520.skin.Input;
	import huachenxing.mimi520.skin.Text;

	public class QueryWindowWidget extends WindowWidget
	{
		private var _dateInput_1:Input;
		private var _dateInput_2:Input;
		private var _dateInput_3:Input;
		private var _dateInput_4:Input;
		
		
		override protected function invoke():void
		{
			super.invoke();
			
			var queryDateLabel:Text = new Text("查询月份(格式2015.01)");
			queryDateLabel.color = 0x707c89;
			
			var indexLabel_1:Text = new Text("序号1");
			indexLabel_1.color = 0x707c89;
			
			_dateInput_1 = new Input();
			_dateInput_1.textColor = 0x707c89;
			
			var indexLabel_2:Text = new Text("序号2");
			indexLabel_2.color = 0x707c89;
			
			_dateInput_2 = new Input();
			_dateInput_2.textColor = 0x707c89;
			
			var indexLabel_3:Text = new Text("序号3");
			indexLabel_3.color = 0x707c89;
			
			_dateInput_3 = new Input();
			_dateInput_3.textColor = 0x707c89;
			
			var indexLabel_4:Text = new Text("序号4");
			indexLabel_4.color = 0x707c89;
			
			_dateInput_4 = new Input();
			_dateInput_4.textColor = 0x707c89;
			
			addElement(new Element(queryDateLabel, 0));
			addElement(new Element(indexLabel_1, 1));
			addElement(new Element(_dateInput_1, 2, Fill.HORIZONTAL));
			addElement(new Element(indexLabel_2, 3));
			addElement(new Element(_dateInput_2, 4, Fill.HORIZONTAL));
			addElement(new Element(indexLabel_3, 5));
			addElement(new Element(_dateInput_3, 6, Fill.HORIZONTAL));
			addElement(new Element(indexLabel_4, 7));
			addElement(new Element(_dateInput_4, 8, Fill.HORIZONTAL));
		}
		
		override protected function get title():String
		{
			return "查询设置";
		}
		
		override protected function get rect():Rectangle
		{
			return new Rectangle(Number.MIN_VALUE, Number.MIN_VALUE, 300, 340);
		}
		
		override protected function get close():Class
		{
			return CloseQueryWindowCommand;
		}
		
		
		override protected function enable():void
		{
			var monthVec:Vector.<Date> = QueryModel.monthVec;
			for(var i:int = 0; i < monthVec.length; ++ i)
			{
				var monthDate:Date = monthVec[i];
				var input:Input = this["_dateInput_" + (i + 1)];
				input.text = monthDate.fullYear.toString() + "." +  (monthDate.month + 101).toString().substr(1);
			}
			super.enable();
		}
		
		override protected function disable():void
		{
			super.disable();
			var monthVec:Vector.<Date> = QueryModel.monthVec;
			monthVec.length = 0;
			for(var i:int = 0; i < 4; ++ i)
			{
				try {
					var input:Input = this["_dateInput_" + (i + 1)];
					var month:String = input.text;
					month = StringUtil.trim(month);
					if(month.length < 6 || month.length > 7) continue;
					var monthArr:Array = month.split(".");
					if(monthArr.length != 2) continue;
					var monthDate:Date = new Date(int(monthArr[0]), int(monthArr[1]) - 1);
					monthVec.push(monthDate);
				} catch(e) { continue; }
			}
		}
	}
}